﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//------------//
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//....................

namespace QLKTX1._0.DAO
{
    class KhungGia_DienNuocDAO
    {
        public static List<KhungGiaDienNuocDTO> dsKhungGia_DienNuoc()
        {
            List<KhungGiaDienNuocDTO> dsKhungGia_DienNuoc = new List<KhungGiaDienNuocDTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM khungGia_dienNuoc");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                KhungGiaDienNuocDTO khungGiaDienNuoc = new KhungGiaDienNuocDTO();

                khungGiaDienNuoc.MaKhungGiaDienNuoc  = dt.Rows[i]["maKhungGia_dienNuoc"].ToString();

                khungGiaDienNuoc.MoTa  = dt.Rows[i]["moTa"].ToString();

                // KhuDTO k = new KhuDTO(dt.Rows[i]["maKhu"].ToString(), dt.Rows[i]["tenKhu"].ToString());

                dsKhungGia_DienNuoc.Add(khungGiaDienNuoc);
            }
            return dsKhungGia_DienNuoc;
        }
        // Ham Insert
        public static bool themKhungGiaDienNuoc(KhungGiaDienNuocDTO  khungGiaDienNuoc)
        {

            ConnectDB con = new ConnectDB();// dung DB

            return con.executeQuery("INSERT INTO khungGia_dienNuoc(maKhungGia_dienNuoc,moTa) VALUES('" + khungGiaDienNuoc.MaKhungGiaDienNuoc + "','" + khungGiaDienNuoc.MoTa + "')");

        }
        //Ham delete
        public static bool xoaKhungGiaDienNuoc(KhungGiaDienNuocDTO khungGiaDienNuoc)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("DELETE FROM khungGia_dienNuoc WHERE maKhungGia_dienNuoc='" + khungGiaDienNuoc.MaKhungGiaDienNuoc  + "'");
        }
        //ham update
        public static bool capNhatKhungGiaDienNuoc(KhungGiaDienNuocDTO khungGiaDienNuoc)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("UPDATE khungGia_dienNuoc set moTa='" + khungGiaDienNuoc.MoTa + "' WHERE maKhungGia_dienNuoc='" + khungGiaDienNuoc.MaKhungGiaDienNuoc + "'");
        }
    }
}
